'==================================================================================================
'	Author		David Segura
'	URL			http://winpeguy.com/
'	Source		http://winpe.codeplex.com/
'	Version		20130910
'==================================================================================================
'	Purpose:
'	Microsoft Deployment Toolkit related subroutines and functions
'==================================================================================================
'	File Locations in Windows:
'	%DeployRoot%\Boot\+WinPE\Menu\Scripts\MS-MDT.vbs
'==================================================================================================
'	File Location in WinPE:
'	X:\Menu\Scripts\MS-MDT.vbs
'==================================================================================================
'	Configuration:
'	None.  Editing this file is not recommended
'==================================================================================================
'	Change Log:
'	20130910	Codeplex Beta
'==================================================================================================
	Sub subLiteTouch
		
		intCleanInstall = 	Msgbox("If this is a Clean Install and you do not need any data on the Hard Drive" & vbCrLf & _
							"It is strongly recommended that the drive be formatted" & vbCrLf & _
							"" & vbCrLf & _
							"Do you want to format the Primary Hard Drive?",36,MsgBoxTitleShort & "LiteTouch Deployment")
		
		If intCleanInstall = vbYes Then
		
			intCleanInstall2 = 	Msgbox("Remove any USB Drives before pressing OK" & vbCrLf & _
								"" & vbCrLf & _
								"Do you want to continue and format the Primary Hard Drive?",36,MsgBoxTitleShort & "LiteTouch Deployment")
		Else
			RunLiteTouch = "YES"
		End If

		If intCleanInstall = vbYes and intCleanInstall2 = vbYes Then
			intDriveFormat = InputBox("To proceed with the Primary Hard Drive format" & vbCrLf & _
									"Type the word format in lower case in the box below",MsgBoxTitleShort & "LiteTouch Deployment")

			If (intDriveFormat = "format") Then
				subDiskpartHD
				RunLiteTouch = "YES"
				MsgBox	"If you are imaging from a USB Drive, you may plug it back in at this time" & vbCrLf & _
						"" & vbCrLf & _
						"Wait at least 10 seconds before pressing OK" & vbCrLf & _
						"" & vbCrLf & _
						"If you were booting from a USB Drive only, there is no need to plug it back in",64,MsgBoxTitleShort & "LiteTouch Deployment"
			Else
				MsgBox "The word was incorrectly typed or the Cancel button was pressed.  No action will be taken.",16,MsgBoxTitleShort & "LiteTouch Deployment"
			End If
		End If
		
		If RunLiteTouch = "YES" Then
			subLiteTouchCleanup
			sCmd = "cscript.exe " & envSystemDrive & "\Deploy\Scripts\LiteTouch.wsf"
			objShell.Run sCmd
		End If
	End Sub
'==================================================================================================
	Sub subTrace
		If objFSO.FileExists(envSystem32 & "\CMTrace.exe") Then
			If objFSO.FileExists(strSystemDrive & "\MININT\SMSOSD\OSDLOGS\BDD.LOG") Then
				strLogFile = strSystemDrive & "\MININT\SMSOSD\OSDLOGS\BDD.LOG"
				sCmd = "CMTrace " & "" & strLogFile & ""
				objShell.Run sCmd
			End If
			If objFSO.FileExists("C:\Windows\Temp\DeploymentLogs\BDD.LOG") Then
				strLogFile = """C:\Windows\Temp\DeploymentLogs\BDD.LOG"""
				sCmd = "CMTrace " & "" & strLogFile & ""
				objShell.Run sCmd
			End If
			If objFSO.FileExists("C:\MININT\SMSOSD\OSDLOGS\BDD.LOG") Then
				strLogFile = "C:\MININT\SMSOSD\OSDLOGS\BDD.LOG"
				sCmd = "CMTrace " & "" & strLogFile & ""
				objShell.Run sCmd
			End If
			If objFSO.FileExists("V:\MININT\SMSOSD\OSDLOGS\BDD.LOG") Then
				strLogFile = "V:\MININT\SMSOSD\OSDLOGS\BDD.LOG"
				sCmd = "CMTrace " & "" & strLogFile & ""
				objShell.Run sCmd
			End If
			If objFSO.FileExists("W:\MININT\SMSOSD\OSDLOGS\BDD.LOG") Then
				strLogFile = "W:\MININT\SMSOSD\OSDLOGS\BDD.LOG"
				sCmd = "CMTrace " & "" & strLogFile & ""
				objShell.Run sCmd
			End If
			
			Set colProcessList = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = 'cmtrace.exe'")
			ProcessCount = colProcessList.count
			
			If ProcessCount = 0 Then
				strLogFile = strSystemDrive & "\MININT\SMSOSD\OSDLOGS\BDD.LOG"
				sCmd = "CMTrace " & "" & strLogFile & ""
				objShell.Run sCmd
			End If

		Else
			MsgBox "Cannot find " & envSystem32 & "\CMTrace.exe" & vbCrLf & "" & vbCrLf & _
			"Microsoft Trace does not appear to be installed",16,MsgBoxTitle
		End If
	End Sub
'==================================================================================================
Sub subDiskpartHD
	If objFSO.FileExists(envTemp & "\diskpartHD.txt") Then
		objFSO.DeleteFile(envTemp & "\diskpartHD.txt")
	End If
	
	Set objTextStream = objFSO.OpenTextFile(envTemp & "\diskpartHD.txt", 2, True)
	objTextStream.WriteLine "LIST DISK"
	objTextStream.WriteLine "SELECT DISK 0"
	objTextStream.WriteLine "CLEAN"
	objTextStream.WriteLine "EXIT"
	objTextStream.Close

	If objFSO.FileExists(envTemp & "\diskpartHD.txt") Then
		sCmd = "diskpart /s " & envTemp & "\diskpartHD.txt"
		objShell.Run sCmd, 1, True
	End If
End Sub

Sub subLiteTouchCleanup
	If objFSO.FolderExists(strSystemDrive & "\MININT") Then
		objFSO.DeleteFolder(strSystemDrive & "\MININT")
	End If
	If objFSO.FolderExists(strSystemDrive & "\Windows\Temp\DeploymentScripts") Then
		objFSO.DeleteFolder(strSystemDrive & "\Windows\Temp\DeploymentScripts")
	End If
	If objFSO.FolderExists(strSystemDrive & "\Windows\Temp\SMSTSLog") Then
		objFSO.DeleteFolder(strSystemDrive & "\Windows\Temp\SMSTSLog")
	End If
	If objFSO.FolderExists("C:\MININT") Then
		objFSO.DeleteFolder("C:\MININT")
	End If
	If objFSO.FolderExists("D:\MININT") Then
		objFSO.DeleteFolder("D:\MININT")
	End If
	If objFSO.FolderExists("V:\MININT") Then
		objFSO.DeleteFolder("V:\MININT")
	End If
	If objFSO.FolderExists("W:\MININT") Then
		objFSO.DeleteFolder("W:\MININT")
	End If
	If objFSO.FolderExists("C:\_SMSTaskSequence") Then
		objFSO.DeleteFolder("C:\_SMSTaskSequence")
	End If
	If objFSO.FolderExists("D:\_SMSTaskSequence") Then
		objFSO.DeleteFolder("D:\_SMSTaskSequence")
	End If
	If objFSO.FolderExists("V:\_SMSTaskSequence") Then
		objFSO.DeleteFolder("V:\_SMSTaskSequence")
	End If
	If objFSO.FolderExists("W:\_SMSTaskSequence") Then
		objFSO.DeleteFolder("W:\_SMSTaskSequence")
	End If
End Sub